home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 1.1 / SGI EnlightenDSM 1.1.iso / sco5x / emd / bin / e_putrc < prev    next >
Text File  |  1998-07-01  |  8KB  |  338 lines

  1. #!/bin/sh 
  2. #
  3. # Script: e_putrc
  4. #
  5. # Add a reference to start_enl_daemons to the appropriate rc file.
  6. #
  7. # Copyright (c) 1990-1998 Enlighten Software Solutions, Inc.
  8. # All Rights Reserved
  9.  
  10. PATH=/bin:/usr/bin:/etc:/usr/ucb:/usr/bsd:/usr/etc:$PATH
  11. export PATH
  12.  
  13. appName=`basename $0`
  14.  
  15. errorCheck () {
  16.     if [ $? -ne 0 ] ; then
  17.         echo "$appName: Fatal: Could not add Enlighten reference to rc file." 1>&2
  18.         exit 1
  19.     fi
  20. }
  21.  
  22. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. # build_rc - Build a SVr5 compliant rc2.d script.
  24. #            (currently just used for HP-UX 10.x)
  25. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  26.  
  27. buildrc () {
  28.  
  29.     if [ -f "$LINK_DIR/$LINK_FILE" ] ; then
  30.         mv $LINK_DIR/$LINK_FILE /tmp/$LINK_FILE.old ; errorCheck
  31.         echo "$appName: Archived $LINK_DIR/$LINK_FILE to /tmp/$LINK_FILE.old"
  32.     fi
  33.     
  34.     if [ -f "$LINK_DIR_STOP/$LINK_FILE_STOP" ] ; then
  35.         mv $LINK_DIR_STOP/$LINK_FILE_STOP /tmp/$LINK_FILE_STOP.old ; errorCheck
  36.         echo "$appName: Archived $LINK_DIR_STOP/$LINK_FILE_STOP to /tmp/$LINK_FILE_STOP.old"
  37.     fi
  38.     
  39.     if [ -f "$RC_DIR/$RC_FILE" ] ; then
  40.         mv $RC_DIR/$RC_FILE /tmp/$RC_FILE.old ; errorCheck
  41.         echo "$appName: Archived $RC_DIR/$RC_FILE to /tmp/$RC_FILE.old"
  42.     fi
  43.  
  44.     cat << eof > $RC_DIR/$RC_FILE
  45. #!/bin/sh
  46. # Script: $RC_DIR/$RC_FILE
  47. # Copyright (c) 1990-1998 Enlighten Software Solutions, Inc.
  48.  
  49. PATH=/sbin:/usr/sbin:/bin:/usr/bin ; export PATH
  50.  
  51. # Find start_enl_daemons.
  52.  
  53. enlDir=\`egrep "^enlighten=" /etc/enlighten | cut "-d=" -f2-\`
  54. emdDir=\`egrep "^emd_dir=" /etc/enlighten | cut "-d=" -f2-\`
  55. startLic=\$emdDir/FLEXlm/start_dsmld
  56. stopLic=\$emdDir/FLEXlm/stop_dsmld
  57. startDaemons=\$enlDir/bin/start_enl_daemons
  58. stopDaemons=\$enlDir/bin/stop_enl_daemons
  59. logFile=\$enlDir/logs/startup.log
  60.  
  61. rc=0
  62.  
  63. case \$1 in
  64.  
  65. start_msg)
  66.     echo "Start EnlightenDSM daemons"
  67.     ;;
  68. stop_msg)
  69.     echo "Stop EnlightenDSM daemons"
  70.     ;;
  71. start)
  72.     if [ -n "\$emdDir" ] ; then
  73.         if [ ! -f \$startLic ] ; then
  74.             echo "\$0: \$startLic was missing."
  75.             rc=1
  76.         elif [ ! -x \$startLic ] ; then
  77.             echo "\$0: \$startLic was not executible."
  78.             rc=1
  79.         else
  80.             echo "Starting $startLic..."
  81.             nohup sh -c "su dbenl -c '\$startLic' > \$logFile 2>&1 &"
  82.             rc=\$?
  83.         fi
  84.     fi
  85.  
  86.     if [ ! -f \$startDaemons ] ; then
  87.         echo "\$0: \$startDaemons was missing."
  88.         rc=1
  89.     elif [ ! -x \$startDaemons ] ; then
  90.         echo "\$0: \$startDaemons was not executible."
  91.         rc=1
  92.     else
  93.         echo "Starting EnlightenDSM daemons..."
  94.         nohup sh -c "\$startDaemons > \$logFile 2>&1 &"
  95.         rc=\$?
  96.     fi
  97.     ;;
  98. stop)
  99.     if [ -n \$emdDir ] ; then
  100.         if [ ! -f \$stopLic ] ; then
  101.             echo "\$0: \$stopLic was missing."
  102.             rc=1
  103.         elif [ ! -x \$stopLic ] ; then
  104.             echo "\$0: \$stopLic was not executible."
  105.             rc=1
  106.         else
  107.             su dbenl -c "\$stopLic"
  108.             rc=\$?
  109.         fi
  110.     fi
  111.  
  112.     if [ ! -f \$stopDaemons ] ; then
  113.         echo "\$0: \$stopDaemons was missing."
  114.         rc=1
  115.     elif [ ! -x \$stopDaemons ] ; then
  116.         echo "\$0: \$stopDaemons was not executible."
  117.         rc=1
  118.     else
  119.         \$stopDaemons
  120.         rc=\$?
  121.     fi
  122.     ;;
  123. *)
  124.     echo "\$0: Usage: \$0 {start|stop}"
  125.     ;;
  126. esac
  127. exit \$rc
  128. eof
  129.  
  130.     if [ -n "$LINK_DIR" ] ; then
  131.         ln -s $RC_DIR/$RC_FILE $LINK_DIR/$LINK_FILE
  132.         errorCheck
  133.         echo $LINK_DIR/$LINK_FILE >> $enl_manifest
  134.     fi
  135.  
  136.     if [ -n "$LINK_DIR_STOP" ] ; then
  137.         ln -s $RC_DIR/$RC_FILE $LINK_DIR_STOP/$LINK_FILE_STOP
  138.         errorCheck
  139.         echo $LINK_DIR_STOP/$LINK_FILE_STOP >> $enl_manifest
  140.     fi
  141.  
  142.     echo $RC_DIR/$RC_FILE >> $enl_manifest
  143. }
  144.  
  145. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  146. # add2rc - add the comment and nohup lines to the RC file
  147. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  148.  
  149. add2rc () {
  150.  
  151.     if [ -f $RC_DIR/$RC_FILE ] ; then
  152.         daemonName=`basename $startDaemonsScript`
  153.  
  154.         mv $RC_DIR/$RC_FILE $RC_DIR/$RC_FILE.old ; errorCheck
  155.         echo "$appName: Archived $RC_DIR/$RC_FILE to $RC_DIR/$RC_FILE.old.";
  156.         egrep -v "S92startenl|$daemonName" $RC_DIR/$RC_FILE.old \
  157.             > $RC_DIR/$RC_FILE
  158.         errorCheck
  159.     else
  160.         touch $RC_DIR/$RC_FILE
  161.     fi
  162.  
  163.     if [ "$start_lic" -eq 1 ] ; then
  164.         echo "echo Invoking $lic_script..." >> $RC_DIR/$RC_FILE
  165.         echo "nohup sh -c 'su dbenl -c \"$lic_script\" > $LOG 2>&1 &' " >> $RC_DIR/$RC_FILE
  166.         errorCheck
  167.     fi
  168.         
  169.     
  170.     if [ -z "`grep $startDaemonsScript $RC_DIR/$RC_FILE`" ] ; then
  171.         echo "echo Invoking $startDaemonsScript..." >> $RC_DIR/$RC_FILE
  172.         echo "nohup sh -c '$startDaemonsScript > $LOG 2>&1 &' " >> $RC_DIR/$RC_FILE
  173.         errorCheck
  174.     fi
  175. }
  176.  
  177. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  178. # HP-UX 9.0x version of add2rc
  179. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  180.  
  181. hpadd2rc() {
  182.     if [ "$start_lic" -eq 1 ] ; then
  183.         if [ -z "`grep $lic_script $RC_DIR/$RC_FILE`" ] ; then
  184.             daemonName=`basename $startDaemonsScript`
  185.             mv $RC_DIR/$RC_FILE $RC_DIR/$RC_FILE.old
  186.             errorCheck
  187.             egrep -v "$daemonName|$lic_script|S92startenl" $RC_DIR/$RC_FILE.old \
  188.                 > $RC_DIR/$RC_FILE
  189.             errorCheck
  190.  
  191.             awk " /^localrc\(\)/ { f = 1 }
  192.             f == 1 && /^}/ { print \"\\n\\techo Invoking $lic_script...\\n\\tsu dbenl -c '$lic_script > $LOG 2>&1 &' \" ; f = 0 }
  193.             { print }
  194.             " < $RC_DIR/$RC_FILE > $RC_DIR/$RC_FILE.new
  195.              mv $RC_DIR/$RC_FILE.new $RC_DIR/$RC_FILE 
  196.             errorCheck
  197.         fi
  198.     fi
  199.  
  200.     if [ -z "`grep $startDaemonsScript $RC_DIR/$RC_FILE`" ] ; then
  201.         daemonName=`basename $startDaemonsScript`
  202.  
  203.         mv $RC_DIR/$RC_FILE $RC_DIR/$RC_FILE.old
  204.         errorCheck
  205.         egrep -v "$daemonName|S92startenl" $RC_DIR/$RC_FILE.old \
  206.             > $RC_DIR/$RC_FILE
  207.         errorCheck
  208.  
  209.         awk " /^localrc\(\)/ { f = 1 }
  210.         f == 1 && /^}/ { print \"\\n\\techo Invoking $startDaemonsScript...\\n\\tnohup sh -c '$startDaemonsScript > $LOG 2>&1 &' \" ; f = 0 }
  211.         { print }
  212.         " < $RC_DIR/$RC_FILE > $RC_DIR/$RC_FILE.new
  213.         mv $RC_DIR/$RC_FILE.new $RC_DIR/$RC_FILE 
  214.         errorCheck
  215.     fi
  216. }
  217.  
  218. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  219. # Start of e_putrc
  220. # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  221.  
  222. if [ -z "$ENLIGHTEN" ] ; then
  223.     ENLIGHTEN=`egrep "^enlighten=" /etc/enlighten | cut '-d=' -f2-`
  224. fi
  225.  
  226. if [ -z "$ENLIGHTEN" -o ! -d $ENLIGHTEN/bin ] ; then
  227.     #
  228.     # Maybe it's an EMD-only installation.
  229.     #
  230.     EMD_DIR=`egrep "^emd_dir=" /etc/enlighten | cut '-d=' -f2-`
  231.     if [ -z "$EMD_DIR" -o ! -d $EMD_DIR/bin ] ; then
  232.         echo "$appName: Fatal: The ENLIGHTEN variable was not set correctly." 1>&2
  233.         exit 1
  234.     else
  235.         ENLIGHTEN=$EMD_DIR ; export ENLIGHTEN
  236.     fi
  237. fi
  238.  
  239. enl_manifest=${ENLIGHTEN}/manifest
  240.  
  241. #
  242. # Find emd\-dir to see if licensing should be started
  243. #
  244. if [ -z "$EMD_DIR" ] ; then
  245.     EMD_DIR=`egrep "^emd_dir=" /etc/enlighten | cut '-d=' -f2-`
  246. fi
  247.  
  248. if [ -n "$EMD_DIR" ] ; then
  249.     flex_dir="$EMD_DIR/FLEXlm"
  250.     lic_script="$flex_dir/start_dsmld"
  251.     if [ ! -f "$lic_script" ] ; then
  252.         echo "$appName:Unable to find $lic_script."
  253.         start_lic=0
  254.     else
  255.         start_lic=1
  256.     fi
  257. else
  258.     start_lic=0
  259. fi
  260.  
  261.  
  262. if [ -d $ENLIGHTEN/logs ] ; then
  263.     LOG=$ENLIGHTEN/logs/startup.log
  264. else
  265.     LOG=/tmp/enlighten.log
  266. fi
  267.  
  268. startDaemonsScript=$ENLIGHTEN/bin/start_enl_daemons
  269. stopDaemonsScript=$ENLIGHTEN/bin/stop_enl_daemons
  270.  
  271. if [ ! -x $startDaemonsScript ] ; then
  272.     echo "$appName: Fatal: The script $startDaemonsScript is missing." 1>&2
  273.     exit 1
  274. fi
  275.  
  276. case `uname -s` in
  277.     OSF1 )
  278.         RC_DIR=/sbin/init.d
  279.         RC_FILE=enlighten
  280.         LINK_FILE=S920enlighten
  281.         LINK_DIR=/sbin/rc3.d
  282.         LINK_FILE_STOP=K12enlighten
  283.         LINK_DIR_STOP=/sbin/rc0.d
  284.         buildrc
  285.         ;;
  286.  
  287.     HP-UX ) 
  288.         case `uname -r` in
  289.             ?.10.* )
  290.                 RC_DIR=/sbin/init.d
  291.                 RC_FILE=enlighten
  292.                 LINK_FILE=S920enlighten
  293.                 LINK_DIR=/sbin/rc2.d
  294.                 LINK_FILE_STOP=K12enlighten
  295.                 LINK_DIR_STOP=/sbin/rc0.d
  296.                 buildrc
  297.                 ;;
  298.             * )
  299.                 RC_DIR=/etc
  300.                 RC_FILE=rc
  301.                 hpadd2rc
  302.                 ;;
  303.         esac
  304.         ;;
  305.     IRIX* )
  306.         RC_DIR=/etc/init.d
  307.         RC_FILE=enlighten
  308.         LINK_FILE=S920enlighten
  309.         LINK_DIR=/etc/rc2.d
  310.         LINK_FILE_STOP=K12enlighten
  311.         LINK_DIR_STOP=/etc/rc0.d
  312.         buildrc
  313.         ;;
  314.     AIX )
  315.         RC_DIR=/etc
  316.         RC_FILE=rc.nfs
  317.         add2rc
  318.         ;;
  319.     * )
  320.         if [ -d /etc/rc2.d ] ; then
  321.             RC_DIR=/etc/rc2.d
  322.             RC_FILE=S920enlighten
  323.             buildrc
  324.         else
  325.             RC_DIR=/etc
  326.             RC_FILE=rc.local
  327.             add2rc
  328.         fi
  329.         ;;
  330. esac
  331.  
  332. chmod 744 $RC_DIR/$RC_FILE
  333. errorCheck
  334.  
  335. echo "$appName: Enlighten reference successfully added to $RC_DIR/$RC_FILE"
  336. exit 0 
  337.  
  338.